
<div class="x_panel">
  <div class="x_content" style="display: block;">
    <!--表格主体内容-->
    <div class="row-fluid">
      <form action="/order/refund.html" method="get">
        <label class="control-label">订单号</label>
        <input type="text" class="form-control-new" name="form[order_no]" value="{if isset($query.order_no)}{$query.order_no}{/if}">
        <label class="control-label">商品号</label>
        <input type="text" class="form-control-new" name="form[goods_id]" value="{if isset($query.goods_id)}{$query.goods_id}{/if}">
        <label class="control-label">商品名称</label>
        <input type="text" class="form-control-new" name="form[goods_name]" value="{if isset($query.goods_name)}{$query.goods_name}{/if}">
        <label class="control-label">商品类型</label>
        <select  class="form-control-new" name="form[category_id]" >
          <option {if !isset($query.category_id) || $query.category_id==0}selected="selected"{/if} value="0">全部</option>
          {foreach $category AS $value}
          <option {if isset($query.category_id) && $query.category_id==$value.category_id}selected="selected"{/if} value="{$value.category_id}">{$value.category_name}</option>
          {/foreach}
        </select>

        <label class="control-label">下单时间</label>
        <input type="text"  name="form[order_start_time]" value="{if isset($query.order_start_time)}{$query.order_start_time}{/if}" placeholder="开始时间" id="J_dh_start" class="form-control-new" >
        <input type="text"  name="form[order_end_time]" value="{if isset($query.order_end_time)}{$query.order_end_time}{/if}" placeholder="结束时间" id="J_dh_end" class="form-control-new" >
        <label class="control-label">支付时间</label>
        <input type="text"  name="form[pay_start_time]" value="{if isset($query.pay_start_time)}{$query.pay_start_time}{/if}" placeholder="开始时间" id="J_dh_start1" class="form-control-new" >
        <input type="text"  name="form[pay_end_time]" value="{if isset($query.pay_end_time)}{$query.pay_end_time}{/if}" placeholder="结束时间" id="J_dh_end1" class="form-control-new" >

        <button name="submit" type="submit" class="btn btn-primary" value="search">查询</button>
        <button name="submit" value="export" type="submit" class="btn btn-primary" >导出</button>
      </form>
      <br>
      <form action="/order/refund.html" method="post" enctype="multipart/form-data" onsubmit="return check()">
        <input type="file" name="refund_file" id="file">
        <button name="submit" value="import" type="submit" class="btn btn-primary" >导入</button>
      </form>

    </div>
    <br>
    <div class="cont">
      <table class="table table-bordered table-striped">
        <thead>
        <tr>
          <th width="100px">退款单号</th>
          <th width="100px">订单号</th>
          <th>支付渠道</th>
          <th>支付渠道订单号</th>
          <th>订单金额</th>
          <th>用户手机号</th>
          <th>退款状态</th>
          <th>退款金额</th>
          <th>退款原因</th>
          <th>退款单生成时间</th>
          <th>退款完成时间</th>
          <th>备注</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $order.lists as $orderitem}
        <tr>
          <td>{$orderitem.refund_no}</td>
          <td>{$orderitem.order_no}</td>
          <td>{$orderitem.pay_type}</td>
          <td>{$orderitem.pay_no}</td>
          <td>{$orderitem.order_amount}</td>
          <td>{$orderitem.mobile}</td>
          <td>
            {if $orderitem.refund_status==1}申请退款{elseif $orderitem.refund_status==2}退款中{elseif $orderitem.refund_status==3}拒绝退款{elseif $orderitem.refund_status==4}完成退款{/if}
          </td>
          <td>{$orderitem.refund_amount}</td>
          <td>{$orderitem.reason}</td>
          <td>{$orderitem.add_time}</td>
          <td>{$orderitem.over_time}</td>
          <td>{$orderitem.refund_remark}</td>
          <td>
            <div class="x_content">
              {if $orderitem.refund_status==1 || $orderitem.refund_status==2}<button class="refund-order btn btn-primary btn-xs" data-title="{if $orderitem.refund_status==1}同意退款{elseif $orderitem.refund_status==2}确认退款完成{/if}" data-refund="{$orderitem.refund_id}" data-order-no="{$orderitem.order_no}" data-goods-name="{$orderitem.goods_name}" data-reason="{$orderitem.reason}" data-refund-amount="{$orderitem.refund_amount}" data-refund-remark="{$orderitem.refund_remark}"> {if $orderitem.refund_status==1}同意退款{elseif $orderitem.refund_status==2}确认退款{/if}</button>{/if}
              <button class="btn btn-danger btn-xs" data-toggle="dropdown">拒绝退款
                <i class="icon-angle-down"></i></button>
              <ul class="dropdown-menu">
                <li><a href="{eval U(['order/reject-refund','refund_id'=>$orderitem.refund_id])}">确定</a></li>
                <li><a href="javascript:;">取消</a></li>
              </ul>
            </div>
          </td>
        </tr>

        {/foreach}
        </tbody>
      </table>
      <!--分页-->
      {Yii::$app->view->render('/com/pager.php',['pager'=>$order.pager])}

    </div>
  </div>
</div>

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="detail-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header" style="border:none">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel"></h4>
      </div>
      <div class="modal-body">
        <div class="loaders">
          <div class="ball-spin-fade-loader">
            订单号：<span id="orderno"></span>&nbsp;&nbsp;&nbsp;&nbsp;商品名称：<span id="goodsname"></span><br>
            <div id="needhide">退款原因:<span id="reason"></span></div>
            <br>
            退款金额：<b style="color:red">*</b><input required="required" id="refund_amount" type="text" value="" />
            <br>
            备注：<textarea id="refund_remark"></textarea>
          </div>
        </div>
        <div id="modal-dyn"></div>
      </div>
      <div class="modal-footer" style="border:none;">
        <button id="refundorder" type="button" class="copy btn btn-secondary" data="">提交</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript" src="{$theme}/libs/js/datepicker/bootstrap-datetimepicker.min.js"></script>

<script>
    $(".refund-order").click(function () {
        $('#refundorder').attr('data',$(this).attr('data-refund'));
        $('#myModalLabel').text($(this).attr('data-title'));
        if($(this).attr('data-title')=="同意退款"){
            $('#needhide').show();
        }else{
            $('#needhide').hide();
        }
        $('#orderno').text($(this).attr('data-goods-no'));
        $('#goodsname').text($(this).attr('data-goods-name'));
        $('#reason').text($(this).attr('data-reason'));
        $('#refund_amount').val($(this).attr('data-refund-amount'));
        $('#refund_remark').val($(this).attr('data-refund-remark'));
        $('#detail-modal').modal('show');
    })

    $("#refundorder").click(function () {
        var refund_id = $(this).attr('data');
        var refund_amount = $('#refund_amount').val();
        if(!refund_amount){
            alert('请填写退款金额');
            return false;
        }
        var refund_remark = $('#refund_remark').val();
        var url = "{['order/refund-order']|U}";
        $.post(url, 'refund_id='+refund_id+'&refund_amount='+refund_amount+'&refund_remark='+refund_remark, function (data) {
            window.location.reload();
        },'json');
        $('#detail-modal').modal('hide');
    })

    var startDate = $('#J_dh_start').datetimepicker({
        format: "yyyy-MM-dd",
        autoclose: true,
        todayBtn: true,
        minView: 2,
    })

    var endDate = $('#J_dh_end').datetimepicker({
        format: "yyyy-MM-dd",
        autoclose: true,
        todayBtn: true,
        minView: 2,
    })

    var startDate = $('#J_dh_start1').datetimepicker({
        format: "yyyy-MM-dd",
        autoclose: true,
        todayBtn: true,
        minView: 2,
    })

    var endDate = $('#J_dh_end1').datetimepicker({
        format: "yyyy-MM-dd",
        autoclose: true,
        todayBtn: true,
        minView: 2,
    })
    function check() {
        if($('#file').val().length){
            return true;
        }else{
            alert("请选择上传文件");
            return false;
        }
    }
</script>
